package pa3.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class HostController {
	private HostModel model;
	private HostViewNew view;
	
	public HostController(String hostName, int failureProbability){
		this.view = new HostViewNew(hostName, failureProbability);
		view.setHostStatus("active");
		this.model = new HostModel(this, hostName, failureProbability);	
		addActionListeners();
	}

	private void addActionListeners() {
		this.view.getKillButton().addActionListener(new KillButtonActionListener());
	}

	/*
	public void updateProgressbarFor(String hostName, int i) {
		view.updateProgressBar(hostName, i);
		
	}

	public void addNewProgressbarFor(String hostName) {
		view.addProgressBar(hostName);
	}

	public void removeProgressbarFor(String host) {
		view.removeProgressBar(host);
	}
	*/
	public void setCrashed(boolean isCrashed) {
		if(isCrashed)
			view.setHostStatus("crashed");
		else view.setHostStatus("active");
	}

	public void setLogString(String log) {
		view.setLogString(log);		
	}
	
	class KillButtonActionListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			HostController.this.model.crashHost();
		}
		
	}

}
